package com.emflant.common;

import java.math.BigDecimal;

public class EntNumber {
	
	public static int DIVIDE_DEFAULT_SCALE = 16;
	private BigDecimal number;
	
	public EntNumber(String val) {
		number = new BigDecimal(val);
	}
	
	public EntNumber(BigDecimal val){
		this.number = val;
	}
	
	public EntNumber(double val){
		this.number = BigDecimal.valueOf(val);
	}
	
	public static void setScale(int scale){
		DIVIDE_DEFAULT_SCALE = scale;
	}
	
	public EntNumber add(EntNumber val){
		return new EntNumber(this.number.add(val.number));
	}
	
	public String toString(){
		return number.toPlainString();
	}

	public EntNumber divide(EntNumber val){
		return new EntNumber(this.number.divide(val.number, DIVIDE_DEFAULT_SCALE, BigDecimal.ROUND_HALF_UP));
	}
	
	public EntNumber pow(int n){
		return new EntNumber(number.pow(n));
	}
	
	public EntNumber abs(){
		return new EntNumber(number.abs());
	}
	
	public int compare(EntNumber val){
		return number.compareTo(val.number);
	}
	
	public int compare(int val){
		return number.compareTo(new BigDecimal(val));
	}
	
	public EntNumber multiply(EntNumber val){
		return new EntNumber(number.multiply(val.number));
	}
	
	public EntNumber subtract(EntNumber val){
		return new EntNumber(number.subtract(val.number));
	}
}
